package com.example.demo.controller

import com.example.demo.service.BedService
import com.example.demo.utils.MResult
import com.example.demo.vo.*
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import io.swagger.annotations.ApiSort
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/medical")
@Api(tags = ["床头卡接口"])
@ApiSort(value = 2)
class BedsideBedCardController @Autowired constructor(
    private val mBedService: BedService
) {

    @ApiOperation(value = "连接测试")
    @PostMapping("/connect/test")
    fun connectTest(): MResult<String> {
        return MResult<String>().resultMsage("连接成功")
    }

    @ApiOperation(value = "床头卡信息")
    @GetMapping("/getBedCardInfo")
    fun getBedCardInfo(
        @RequestParam("deptCode") @ApiParam("科室编号") deptCode: String,
        @RequestParam("bedCode") @ApiParam("床位编号") bedCode: String
    ): MResult<BedInfoVo>? {
        mBedService.getBedCardInfo(deptCode, bedCode)?.let {
            return MResult<BedInfoVo>().result(it)
        } ?: return MResult<BedInfoVo>().nullData()
    }

    @ApiOperation(value = "绑定床位")
    @PostMapping("/bindToBed")
    fun bindToBed(
        @RequestParam("deptCode") @ApiParam("科室编号") deptCode: String,
        @RequestParam("deptName") @ApiParam("科室名称") deptName: String,
        @RequestParam("bedCode") @ApiParam("床位编号") bedCode: String,
        @RequestParam("bedName") @ApiParam("床位名称") bedName: String,
        @RequestParam("deviceNo") @ApiParam("设备号") deviceNo: String,
        @RequestParam("deviceMac") @ApiParam("设备MAC地址") deviceMac: String,
        @RequestParam("deviceIp") @ApiParam("设备IP地址") deviceIp: String,
        @RequestParam("appVersion") @ApiParam("设备APP版本") appVersion: String,
        @RequestParam("deviceType") @ApiParam("设备类型") deviceType: String
    ): MResult<DeviceVo>? {
        mBedService.getBindToBed(
            deptCode,
            deptName, bedCode, bedName,
            deviceNo, deviceMac, deviceIp,
            appVersion, deviceType
        )?.let {
            return MResult<DeviceVo>().resultMsage("绑定成功")
        } ?: return MResult<DeviceVo>().error("绑定失败")
    }

    @ApiOperation(value = "获取科室列表")
    @PostMapping("/deptlist")
    fun getDeptList(): MResult<List<DeptVo>> {
        mBedService.getDeptList()?.let {
            return MResult<List<DeptVo>>().result(it)
        } ?: return MResult<List<DeptVo>>().error("获取失败")
    }

    @ApiOperation(value = "获取床位列表")
    @PostMapping("/bedtlist")
    fun getBedList(@RequestParam("deptCode") @ApiParam("科室编号") deptCode: String):
            MResult<BedInfoVoList> {
        mBedService.getBedList(deptCode)?.let {
            return MResult<BedInfoVoList>().result(it)
        } ?: return MResult<BedInfoVoList>().error("获取失败")
    }

    @ApiOperation(value = "获取科室设备号")
    @PostMapping("/dept/device/no")
    fun getDeptDeviceNo(deptCode: String): MResult<DeptDeviceNoVO> {
        mBedService.getDeptDiviceNo(deptCode)?.let {
            return MResult<DeptDeviceNoVO>().result(it)
        } ?: return MResult<DeptDeviceNoVO>().error("获取失败")
    }

    @ApiOperation(value = "获取体温记录")
    @PostMapping("/get/termometer/value")
    fun getThermometerValue(id: Int): MResult<TemperatureVo> {
        mBedService.getTermometerValue(id)?.let {
            return MResult<TemperatureVo>().result(it)
        } ?: return MResult<TemperatureVo>().error("获取失败")
    }

    @ApiOperation(value = "获取体温记录列表")
    @PostMapping("/get/termometer/value/list")
    fun getThermometerValueList(deptId: Int?, patientId: Int?, patientName: String?): MResult<List<TemperatureVo>> {
        mBedService.getTermometerValueList(
            deptId, patientId, patientName
        )?.let {
            return MResult<List<TemperatureVo>>().result(it)
        } ?: return MResult<List<TemperatureVo>>().error("获取失败")
    }

    @ApiOperation(value = "添加体温记录")
    @PostMapping("/add/termometer/value")
    fun addTermometerValue(
        patientId: Int?,
        patientName: String?,
        deptId: Int?,
        deptName: String?,
        bedId: Int?,
        bedName: String?,
        date: String?,
        temperature: String?
    ): MResult<Int> {
        mBedService.addTermometerValue(
            patientId,
            patientName,
            deptId,
            deptName,
            bedId,
            bedName,
            date,
            temperature
        )?.let {
            return MResult<Int>().resultMsage("添加成功")
        } ?: return MResult<Int>().error("添加失败")
    }

    @ApiOperation(value = "获取血压记录")
    @PostMapping("/get/pressure/value")
    fun getPressureValue(id: Int): MResult<PressureVo> {
        mBedService.getPressureValue(id)?.let {
            return MResult<PressureVo>().result(it)
        } ?: return MResult<PressureVo>().error("获取失败")
    }

    @ApiOperation(value = "获取血压记录列表")
    @PostMapping("/get/pressure/value/list")
    fun getPressureValueList(deptId: Int?, patientId: Int?, patientName: String?): MResult<List<PressureVo>> {
        mBedService.getPressureValueList(
            deptId, patientId, patientName
        )?.let {
            return MResult<List<PressureVo>>().result(it)
        } ?: return MResult<List<PressureVo>>().error("获取失败")
    }

    @ApiOperation(value = "添加血压记录")
    @PostMapping("/add/pressure/value")
    fun addPressureValue(
        patientId: Int?,
        patientName: String?,
        deptId: Int?,
        deptName: String?,
        bedId: Int?,
        bedName: String?,
        date: String?,
        highPress: String?,
        lowPress: String?,
        heartRate: String?
    ): MResult<Int> {
        mBedService.addPressureValue(
            patientId,
            patientName,
            deptId,
            deptName,
            bedId,
            bedName,
            date,
            highPress,
            lowPress,
            heartRate
        )?.let {
            return MResult<Int>().resultMsage("添加成功")
        } ?: return MResult<Int>().error("添加失败")
    }


    @ApiOperation(value = "获取消费列表")
    @PostMapping("get/feelist")
    fun getFeeList(patientId: String): MResult<List<FeeVo>> {
        mBedService.getFeeList(patientId)?.let {
            return MResult<List<FeeVo>>().result(it)
        } ?: return MResult<List<FeeVo>>().error("获取失败")
    }

    @ApiOperation(value = "获取科室消息")
    @PostMapping("dept/message")
    fun getDeptMessage(deptid: Int?, messageType: String?, start: Int, end: Int): MResult<List<BoardMessageVo>> {
        mBedService.getBoardMessage(deptid, messageType, start, end)?.let {
            return MResult<List<BoardMessageVo>>().result(it)
        } ?: return MResult<List<BoardMessageVo>>().error("获取失败")
    }

}